<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item
          label="款式编码(货号)/SKU编码/商品名称"
          class="myform-item"
        >
          <el-input
            v-model="form.title"
            placeholder="请输入款式编码(货号)/SKU编码/商品名称"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>
        <el-form-item label="供应商" class="myform-item">
          <el-select
            v-model="form.supplier_id"
            placeholder="请选择"
            clearable
            @keyup.enter.native="onSearch"
          >
            <el-option
              v-for="item in factoryList"
              :key="item.supplier_id"
              :label="item.factory_name"
              :value="item.supplier_id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
      <div>
        <!-- <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onEdit()" icon="el-icon-plus"
            >新建</el-button
          >
        </el-form-item> -->
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column
        fixed
        label="款式编码(货号)"
        align="center"
        prop="type_no"
      ></el-table-column>
      <el-table-column fixed label="SKU编码" align="center" prop="size_code">
        <!-- <template scope="{ row }">
          <div v-for="(item,index) in row.size_code" :key="index">
            {{item}}
          </div>
        </template> -->
      </el-table-column>
      <el-table-column label="商品名称" align="center" prop="type_name" fixed>
      </el-table-column>
      <el-table-column label="商品图片" align="center" prop="image">
        <template scope="{ row }">
          <el-image
            v-if="row.image && row.image.length"
            :src="row.image[0]"
            :preview-src-list="row.image"
            fit="contain"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column
        label="品牌"
        align="center"
        prop="brand"
      ></el-table-column>
      <el-table-column
        label="商品属性"
        align="center"
        prop="attribute"
      ></el-table-column>
      <el-table-column
        label="商品分类"
        align="center"
        prop="classification"
      ></el-table-column>
      <el-table-column
        label="供应商"
        align="center"
        prop="factory_name"
      ></el-table-column>
      <el-table-column label="体积重量信息" align="center">
        <el-table-column label="长度(cm)" align="center" prop="long">
        </el-table-column>
        <el-table-column label="宽度(cm)" align="center" prop="wide">
        </el-table-column>
        <el-table-column label="高度(cm)" align="center" prop="high">
        </el-table-column>
        <el-table-column label="体积(cm³)" align="center" prop="volume">
        </el-table-column>
        <el-table-column label="重量(kg)" align="center" prop="weight">
        </el-table-column>
      </el-table-column>
      <el-table-column label="价格信息/元" align="center">
        <el-table-column label="市场吊牌价" align="center" prop="market_price">
        </el-table-column>
        <el-table-column label="基本售价" align="center" prop="basic_price">
        </el-table-column>
        <el-table-column
          label="成本价(采购价)"
          align="center"
          prop="cost_price"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column
        label="备注说明"
        align="center"
        prop="remarks"
      ></el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onEdit(row.id)">编辑</el-button>
          <!-- <el-button type="text" style="color: red" @click="onDelete(row.id)"
            >删除</el-button
          > -->
          <el-button
            type="text"
            style="color: red"
            v-if="row.status == 1"
            @click="onIs(row.id, 0)"
            >禁用</el-button
          >
          <el-button
            type="text"
            style="color: #67c23a"
            v-if="row.status == 0"
            @click="onIs(row.id, 1)"
            >启用</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminOperateGetOrtherProduct"
    />
    <!-- <el-dialog title="新建分类" :visible.sync="dialogVisible" width="30%">
            <el-form :model="tagform" :rules="rules" ref="tagform" label-width="100px">
                <el-form-item label="分类名称" prop="title">
                    <el-input
                        v-model="tagform.title"
                        placeholder="请输入分类名称"
                        clearable
                        style="width:70%"
                    ></el-input>
                </el-form-item>
                <el-form-item label="标签底色" prop="font_color">
                    <el-color-picker v-model="tagform.font_color"></el-color-picker>
                </el-form-item>
                <el-form-item label="排序" prop="listorder">
                    <el-input
                        v-model="tagform.listorder"
                        placeholder="请输入排序"
                        clearable
                        style="width:70%"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="onClickSubmit('tagform')">确 定</el-button>
                </el-form-item>
            </el-form>
        </el-dialog> -->
  </div>
</template>

<script>
import {
  postAdminOperateGetOrtherProduct,
  postHomeCodeGetFactory,
  postAdminOperateDelOrtherProduct,
  postAdminOperateDisablEOrtherProduct,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false, //审核
      factoryList: [],
      form: {
        title: "",
        supplier_id: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postHomeCodeGetFactory();
    this.postAdminOperateGetOrtherProduct(form);
  },
  methods: {
    // 加工厂列表
    postHomeCodeGetFactory() {
      let obj = {
        type:8,
        page: 1,
        size: 1000,
      };
      postHomeCodeGetFactory(obj).then((res) => {
        this.factoryList = res.data;
      });
    },
    // 查看
    onEdit(id) {
      if (!id) {
        this.$router.push({
          name: "OperationalDepartmentNotForSaleEdit",
        });
      } else {
        this.$router.push({
          name: "OperationalDepartmentNotForSaleEdit",
          query: { id },
        });
      }
    },
    async onIs(id, status) {
      let obj = {
        id: id,
        is_disable: status,
      };
      this.$confirm(`确定${status==0?'禁用':'启用'}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminOperateDisablEOrtherProduct(obj);
          let form = this.form;
          this.postAdminOperateGetOrtherProduct(form);
        })
        .catch(() => {});
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      let { form } = this;
      this.$confirm("确定删除该标签种类?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOperateDelOrtherProduct(obj).then((res) => {
            this.postAdminOperateGetOrtherProduct(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 采购列表
    async postAdminOperateGetOrtherProduct(data) {
      this.loading = true;
      this.form = data;
      postAdminOperateGetOrtherProduct(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminOperateGetOrtherProduct(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
